import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Lei
 * @create 2022-05-22 16:51
 */
public class ViewGetBook extends View<ControllerGetBook> {

    private JTextField t;

    public ViewGetBook(Library m, ControllerGetBook c) {
        super(m, c);
        t = new JTextField();
        add(t);
        setLayout(new GridLayout(2,1));
        Button tell_me_the_book_number = new Button("Tell me the book number");
        tell_me_the_book_number.addActionListener(new MyActionListener(this));
        add(tell_me_the_book_number);
    }

    @Override
    public void update() {

    }

    class MyActionListener implements ActionListener {

        private JFrame parent;

        public MyActionListener(JFrame parent) {
            this.parent = parent;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            String book = c.getBook(t.getText());
            JOptionPane.showMessageDialog(parent,book);
        }
    }
}




